/*
 * @Author: ChunLai
 * @Date: 2023-02-22 08:52:08
 * @LastEditTime: 2025-09-05 08:35:32
 * @Description: 全局对话框配置
 * @FilePath: \02.bldinsure\src\utils\globalui.js
 */
import Vue from "vue";
import { Dialog } from "vant";
import router from "@/router";

/**
 * 全局Alert 替换ok
 * @param {*} content
 * @param {*} callback
 * @param {*} btnText
 * @param {*} title
 * 使用: this.$baseAlert('测试', ()=>{console.log("回调函数")});
 * this.$baseAlert(data.msg)
 * this.$baseAlert(``)
 * this.$baseAlert()
 */
Vue.prototype.$baseAlert = (content, callback, btnText) => {
  // console.log('baseAlert');
  Dialog.alert({
    title: "温馨提示",
    message: content,
    messageAlign: "left",
    confirmButtonColor: "#DA251E",
    confirmButtonText: btnText || "确认",
    getContainer: "body",
  }).then(() => {
    if (callback) {
      callback();
    }
  });
};

/**
 * 全局Confirm
 * @param {*} content
 * @param {*} callback1
 * @param {*} callback2
 * @param {*} title
 * @param {*} btnSureText
 * @param {*} btnCancelText
 * 使用: this.$baseConfirm('测试', ()=>{console.log("确定回调函数")},()=>{console.log("取消回调函数")})
 */
Vue.prototype.$baseConfirm = (
  content,
  callback1,
  callback2,
  btnSureText = "",
  btnCancelText = "",
  target = "body"
) => {
  Dialog.confirm({
    title: "温馨提示",
    message: content,
    messageAlign: "left",
    confirmButtonColor: "#DA251E",
    confirmButtonText: btnSureText || "确定",
    cancelButtonColor: "#666666",
    cancelButtonText: btnCancelText || "取消",
    getContainer: target,
  })
    .then(() => {
      if (callback1) {
        callback1();
      }
    })
    .catch(() => {
      if (callback2) {
        callback2();
      }
    });
};

// $backRouter() 替换ok
Vue.prototype.$backRouter = () => {
  router.go(-1);
};

Vue.prototype.$msAlert = (msg = "", label = "规则提示") => {
  store.commit("common/SET_FIELD_MEAN_CONT", {
    label: label,
    desc: msg,
  });
};